package br.ufc.quixada.adrs.dao.config;

import br.ufc.quixada.adrs.util.Msg;
import java.io.Reader;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
import org.slf4j.LoggerFactory;

/**
 *
 * @author jefferson
 */
public final class PostGresMapConfig {

    private static final SqlMapClient sqlMapClient;

    /**
     * Overcomes the default constructor. Utility classes should be final and must not have public constructors.
     */
    private PostGresMapConfig() {
    }

    static {
        try {
            //Definindo o caminho para o SqlMapConfig e criando o reader
            String res = "SqlMapConfig.xml";
            Reader reader = Resources.getResourceAsReader(res);

            //Recuperando o client para o SqlMap
            sqlMapClient = SqlMapClientBuilder.buildSqlMapClient(reader);
        } catch (Exception e) {
            LoggerFactory.getLogger(PostGresMapConfig.class).error(Msg.EXCEPTION_MESSAGE, PostGresMapConfig.class.getSimpleName(), e);
            throw new RuntimeException(e);
        }
    }

    public static SqlMapClient getSqlMapClient() {
        return sqlMapClient;
    }
}
